package com.fengmoxi.ctv.manage;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.fengmoxi.ctv.Const;
import com.fengmoxi.ctv.activity.CameraActivity;

import java.util.Objects;

public class HdmiInReceiver extends BroadcastReceiver {
    private static final String TAG = HdmiInReceiver.class.getSimpleName();

    @Override
    public void onReceive(Context context, Intent intent) {
        if (Objects.equals(intent.getAction(), Const.ACTION_HDMI_IN)) {
            boolean down = intent.getBooleanExtra("down", false);
            Log.i(TAG, "HDMI IN: " + down);
            if (down) {
                Intent i = new Intent(context, CameraActivity.class);
                i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(i);
            } else if (CameraActivity.cameraActivity != null) {
                CameraActivity.cameraActivity.finish();
            }
        }
    }
}